package com.example.flowermall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.flowermall.entity.InvitationOrder;
import com.example.flowermall.entity.Invitaton;
import com.example.flowermall.entity.Orders;
import com.example.flowermall.mapper.InvitationOrderMapper;
import com.example.flowermall.mapper.InvitatonMapper;
import com.example.flowermall.mapper.OrderMapper;
import com.example.flowermall.service.InvitatonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Invitaton)表服务实现类
 *
 * @author mq
 * @since 2025-03-17 14:50:10
 */
@Service("invitatonService")
public class InvitatonServiceImpl implements InvitatonService {
    @Resource
    private InvitatonMapper invitatonMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Invitaton queryById(Integer id) {
        return this.invitatonMapper.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param invitaton 实例对象
     * @return 实例对象
     */
    @Override
    public Invitaton insert(Invitaton invitaton) {
        this.invitatonMapper.insert(invitaton);
        return invitaton;
    }

    /**
     * 修改数据
     *
     * @param invitaton 实例对象
     * @return 实例对象
     */
    @Override
    public Invitaton update(Invitaton invitaton) {
        this.invitatonMapper.update(invitaton);
        return this.queryById(invitaton.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.invitatonMapper.deleteById(id) > 0;
    }

    @Override
    public List<Invitaton> getByUserId(Integer id) {
        LambdaQueryWrapper<Invitaton> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Invitaton::getUserId,id);
        return invitatonMapper.selectList(queryWrapper);
    }

    @Override
    public Boolean deleteByUserId(Integer id) {
        return invitatonMapper.deleteByUserId(id) > 0;
    }
}
